home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / ghostscr / dict.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-05  |  4.7 KB  |  116 lines

  1. /* Copyright (C) 1989, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* dict.h */
  21. /* Interfaces for Ghostscript dictionary package */
  22.  
  23. /********************************
  24.  * NOTE: on MS-DOS systems, the dict stack is stored in the data segment.
  25.  * This leads to large performance gains, at the expense of having to swap
  26.  * the stack explicitly when switching contexts or handling segment under-
  27.  * or overflow (none of which are implemented yet!).
  28.  ********************************/
  29.  
  30. /*
  31.  * Contrary to our usual practice, we expose the (first-level)
  32.  * representation of a dictionary in the interface file,
  33.  * because it is so important that access checking go fast.
  34.  * The access attributes for the dictionary are stored in
  35.  * the contents ref.
  36.  */
  37. struct dict_s {
  38.     ref count;        /* t_integer, # of occupied entries */
  39.     ref keys;        /* t_shortarray or t_array, keys */
  40.     ref values;        /* t_array, values */
  41. };
  42.  
  43. /* Define the maximum size of a dictionary */
  44. extern const uint dict_max_size;
  45.  
  46. /* Create a dictionary */
  47. extern int dict_create(P2(uint maxlength, ref *dict));
  48.  
  49. /* Return a pointer to a ref that holds the access attributes */
  50. /* for a dictionary. */
  51. #define dict_access_ref(pdref) (&(pdref)->value.pdict->values)
  52. #define check_dict_read(dict) check_read(*dict_access_ref(&dict))
  53. #define check_dict_write(dict) check_write(*dict_access_ref(&dict))
  54.  
  55. /* Look up in a stack of dictionaries.  Store a pointer to the value slot */
  56. /* where found, or to the (value) slot for inserting. */
  57. /* Return 1 if found, 0 if not and there is room for a new entry, */
  58. /* or e_dictfull if the dictionary is full and the key is missing. */
  59. /* The caller is responsible for ensuring key is not a null. */
  60. /* Note that pdbot <= pdtop, and the search starts at pdtop. */
  61. extern int dict_lookup(P4(const ref *pdbot, const ref *pdtop, const ref *key, ref **ppvalue));
  62. /* Look up in just one dictionary. */
  63. #define dict_find(dict,key,ppvalue) dict_lookup(dict,dict,key,ppvalue)
  64.  
  65. /* Enter a key-value pair in a dictionary. */
  66. /* Return 0, e_dictfull, or e_VMerror if the key was a string */
  67. /* and a VMerror occurred when converting it to a name. */
  68. extern int dict_put(P3(ref *dict, const ref *key, const ref *pvalue));
  69.  
  70. /* Remove a key-value pair from a dictionary. */
  71. /* Return 0 or e_undefined. */
  72. extern int dict_undef(P2(ref *dict, const ref *key));
  73.  
  74. /* Return the number of elements in a dictionary. */
  75. extern uint dict_length(P1(const ref *dict));
  76.  
  77. /* Return the capacity of a dictionary. */
  78. extern uint dict_maxlength(P1(const ref *dict));
  79.  
  80. /* Copy one dictionary into another. */
  81. /* Return 0 or e_dictfull. */
  82. extern int dict_copy(P2(const ref *dfrom, ref *dto));
  83.  
  84. /* Grow or shrink a dictionary. */
  85. /* Return 0 or e_dictfull. */
  86. extern int dict_resize(P2(ref *dict, uint newmaxlength));
  87.  
  88. /* Prepare to enumerate a dictionary. */
  89. /* Return an integer suitable for the first call to dict_next. */
  90. extern int dict_first(P1(const ref *dict));
  91.  
  92. /* Enumerate the next element of a dictionary. */
  93. /* index is initially the result of a call on dict_first. */
  94. /* Either store a key and value at eltp[0] and eltp[1] */
  95. /* and return an updated index, or return -1 */
  96. /* to signal that there are no more elements in the dictionary. */
  97. extern int dict_next(P3(const ref *dict, int index, ref *eltp));
  98.  
  99. /****** The remaining definitions take explicit note of ******/
  100. /****** the existence of the dictionary stack. ******/
  101.  
  102. /* Define the dictionary stack and the standard dictionaries. */
  103. extern ref dstack[];
  104. #define systemdict (dstack[0])
  105. #define userdict (dstack[1])
  106.  
  107. /* Define the dictionary stack pointers. */
  108. typedef ref _ds *ds_ptr;
  109. extern ds_ptr dsp, dstop;
  110.  
  111. /* Define a special fast entry for name lookup in the interpreter. */
  112. /* The key is known to be a name; search the entire dict stack. */
  113. /* Return the pointer to the value slot. */
  114. /* If the name isn't found, just return 0. */
  115. extern ref *dict_find_name(P1(ref *pname));
  116.